/**
 * Created by jocky on 09/10/2017.
 */
var rechargeObj = {
    /**
     *
     * @param type
     * @param direction
     */
    lists: function (type, direction) {
        //显示loading
        show_loading_table('recharge_history_table', 7);

        var params = {};
        params.isRender = 2;//ajax调用

        var pageNo_dom = 'recharge_history_pageNo';
        var pageTotal_dom = 'recharge_history_pageTotal';
        params.pageNo = getPageNo(pageNo_dom, pageTotal_dom, type, direction);

        $.each($('#recharge_history_search_form').find('input,select'), function (i, v) {
            var name = $.trim($(v).attr('name'));
            if (name != '') {
                params[name] = $(v).val();
            }
        });

        $.getJSON('/recharge/lists', params, function (json) {
            $("#" + pageNo_dom).val(parseInt(json.pageNo));
            $("#" + pageTotal_dom).html(parseInt(json.pageTotal));
            var sumMoney = parseFloat(json.money[0]['moneys']);
            var tr = "<tr>" +
                "<td><i style='color: red;'>汇总</i></td>" +
                "<td></td>" +
                "<td></td>" +
                "<td></td>" +
                "<td></td>" +
                "<td class='text-right'>" +
                "<i>" + sumMoney+ "</i>" +
                "</td>" +
                "<td></td>"
                "</tr>";
            $.each(json.lists, function (i, v) {
                var status;
                switch (parseInt(v.user_type)) {
                    case 1:
                        status = "<label class='label label-default'>请求中</label>";
                        break;
                    case 2:
                        status = "<label class='label label-success'>成功</label>";
                        break;
                    case 3:
                        status = "<label class='label label-danger'>拒绝</label>";
                        break;
                    default:
                        status = "";
                        break;
                }
                tr += "<tr>";
                tr += "<td><a href='javascript:void(0)' title='查看 / 修改账户信息' onclick=\"traderObj.setForm(" + v.userID + ")\">" + v.loginName + "</a></td>";
                tr += "<td>" + v.accountName + "</td>";
                tr += "<td>" + v.money_order + "</td>";
                tr += "<td class='text-center'>" + convertDate(v.time, 1) + "</td>";
                tr += "<td>" + status + "</td>";
                tr +="<td>"+v.moneys+"</td>";
                tr +="<td class='text-center'> <a onclick='rechargeObj.operate(" + v.money_order + ",1)'>同意</a> | <a onclick='rechargeObj.operate(" + v.money_order + ",0)'>拒绝</a></td>";
                tr += "</tr>";
            });

            $("#recharge_history_table>tbody").html(tr);

        })
    },


    /**
     * 实名详情
     */
    detail: function (uid) {
        $.get('/recharge/detail', {id: uid}, function (html) {
            $('#modal_pop2_title').html('<i>支付成功截图</i>');
            $('#modal_pop2_body').html(html);
            $('#modal_pop2').modal('show');
        })
    },

    /**
     * 实名信息审核操作
     *
     * @param uid
     * @param type 0拒绝，1通过
     */
    operate: function (uid, type) {
        var title = type == 1 ? '确认此订单无误' : '确定拒绝此订单吗？';
        // var errorMsg = $.trim($('#realNameCheckErrorMsg').val());
        var errorMsg="订单金额有误，请确认金额！";
        if (type == 0 && errorMsg == '') {
            var obj = {
                title: '操作通知',
                text: '请填写拒绝原因',
                styling: 'bootstrap3',
                delay: 5000,
                type: 'error'
            };
            new PNotify(obj);
            return;
        }

        swal({
            title: title,
            text: " ",
            type: 'warning',
            showCancelButton: true,
            cancelButtonColor: '#d33',
            cancelButtonText: '取消',
            confirmButtonColor: '#3085d6',
            confirmButtonText: '确定'
        }).then(function () {
            $.getJSON('/recharge/operate', {money_order: uid, type: type, error_msg: errorMsg}, function (json) {
                var obj = {
                    title: '操作通知',
                    text: json.msg,
                    styling: 'bootstrap3',
                    delay: 5000,
                    type: ''
                };

                if (json.code == 1) {
                    obj.type = 'info';
                    obj.addclass = 'dark';
                } else {
                    obj.type = 'error';
                }
                new PNotify(obj);

                $('#modal_pop2').modal('hide');
                realNameCheckObj.lists();
            })
        }).catch(swal.noop);

    }
};